﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;

namespace FluentSql
{
    public class DalSqlDataReader : IDisposable, IDalSqlDataReader
    {
        #region Private Fields

        private SqlDataReader Reader;

        #endregion Private Fields

        #region Public Constructors

        public DalSqlDataReader(SqlDataReader iReader)
        {
            Reader = iReader;
        }

        #endregion Public Constructors

        #region Public Properties

        public int Depth { get { return Reader.Depth; } }

        public int FieldCount { get { return Reader.FieldCount; } }

        public bool HasRows { get { return Reader.HasRows; } }

        public bool IsClosed { get { return Reader.IsClosed; } }

        public int RecordsAffected { get { return Reader.RecordsAffected; } }

        public int VisibleFieldCount { get { return Reader.VisibleFieldCount; } }

        #endregion Public Properties

        #region Public Indexers

        public object this[string name]
        {
            get
            {
                return Reader[name];
            }
        }

        public object this[int i]
        {
            get
            {
                return Reader[i];
            }
        }

        #endregion Public Indexers

        #region Public Methods

        public void Close()
        {
            Reader.Close();
        }

        public void Dispose()
        {
            Reader.Dispose();
        }

        public bool GetBoolean(string column)
        {
            return Reader.GetBoolean(Reader.GetOrdinal(column));
        }

        public byte GetByte(string column)
        {
            return Reader.GetByte(Reader.GetOrdinal(column));
        }

        public long GetBytes(string column, long dataIndex, byte[] buffer, int bufferIndex, int length)
        {
            return Reader.GetBytes(Reader.GetOrdinal(column), dataIndex, buffer, bufferIndex, length);
        }

        public char GetChar(string column)
        {
            return Reader.GetChar(Reader.GetOrdinal(column));
        }

        public long GetChars(string column, long dataIndex, char[] buffer, int bufferIndex, int length)
        {
            return Reader.GetChars(Reader.GetOrdinal(column), dataIndex, buffer, bufferIndex, length);
        }

        public string GetDataTypeName(string column)
        {
            return Reader.GetDataTypeName(Reader.GetOrdinal(column));
        }

        public DateTime GetDateTime(string column)
        {
            return Reader.GetDateTime(Reader.GetOrdinal(column));
        }

        public DateTimeOffset GetDateTimeOffset(string column)
        {
            return Reader.GetDateTimeOffset(Reader.GetOrdinal(column));
        }

        public decimal GetDecimal(string column)
        {
            return Reader.GetDecimal(Reader.GetOrdinal(column));
        }

        public double GetDouble(string column)
        {
            return Reader.GetDouble(Reader.GetOrdinal(column));
        }

        public IEnumerator GetEnumerator()
        {
            return Reader.GetEnumerator();
        }

        public Type GetFieldType(string column)
        {
            return Reader.GetFieldType(Reader.GetOrdinal(column));
        }

        public T GetFieldValue<T>(string column)
        {
            return Reader.GetFieldValue<T>(Reader.GetOrdinal(column));
        }

        public async Task<T> GetFieldValueAsync<T>(string column, CancellationToken cancellationToken)
        {
            return await Reader.GetFieldValueAsync<T>(Reader.GetOrdinal(column));
        }

        public float GetFloat(string column)
        {
            return Reader.GetFloat(Reader.GetOrdinal(column));
        }

        public Guid GetGuid(string column)
        {
            return Reader.GetGuid(Reader.GetOrdinal(column));
        }

        public short GetInt16(string column)
        {
            return Reader.GetInt16(Reader.GetOrdinal(column));
        }

        public int GetInt32(string column)
        {
            return Reader.GetInt32(Reader.GetOrdinal(column));
        }

        public long GetInt64(string column)
        {
            return Reader.GetInt64(Reader.GetOrdinal(column));
        }

        public string GetName(string column)
        {
            return Reader.GetName(Reader.GetOrdinal(column));
        }

        public int GetOrdinal(string name)
        {
            return Reader.GetOrdinal(name);
        }

        public Type GetProviderSpecificFieldType(string column)
        {
            return Reader.GetProviderSpecificFieldType(Reader.GetOrdinal(column));
        }

        public object GetProviderSpecificValue(string column)
        {
            return Reader.GetProviderSpecificValue(Reader.GetOrdinal(column));
        }

        public int GetProviderSpecificValues(object[] values)
        {
            return Reader.GetProviderSpecificValues(values);
        }

        public DataTable GetSchemaTable()
        {
            return Reader.GetSchemaTable();
        }

        public SqlBinary GetSqlBinary(string column)
        {
            return Reader.GetSqlBinary(Reader.GetOrdinal(column));
        }

        public SqlBoolean GetSqlBoolean(string column)
        {
            return Reader.GetSqlBoolean(Reader.GetOrdinal(column));
        }

        public SqlByte GetSqlByte(string column)
        {
            return Reader.GetSqlByte(Reader.GetOrdinal(column));
        }

        public SqlBytes GetSqlBytes(string column)
        {
            return Reader.GetSqlBytes(Reader.GetOrdinal(column));
        }

        public SqlChars GetSqlChars(string column)
        {
            return Reader.GetSqlChars(Reader.GetOrdinal(column));
        }

        public SqlDateTime GetSqlDateTime(string column)
        {
            return Reader.GetSqlDateTime(Reader.GetOrdinal(column));
        }

        public SqlDecimal GetSqlDecimal(string column)
        {
            return Reader.GetSqlDecimal(Reader.GetOrdinal(column));
        }

        public SqlDouble GetSqlDouble(string column)
        {
            return Reader.GetSqlDouble(Reader.GetOrdinal(column));
        }

        public SqlGuid GetSqlGuid(string column)
        {
            return Reader.GetSqlGuid(Reader.GetOrdinal(column));
        }

        public SqlInt16 GetSqlInt16(string column)
        {
            return Reader.GetSqlInt16(Reader.GetOrdinal(column));
        }

        public SqlInt32 GetSqlInt32(string column)
        {
            return Reader.GetSqlInt32(Reader.GetOrdinal(column));
        }

        public SqlInt64 GetSqlInt64(string column)
        {
            return Reader.GetSqlInt64(Reader.GetOrdinal(column));
        }

        public SqlMoney GetSqlMoney(string column)
        {
            return Reader.GetSqlMoney(Reader.GetOrdinal(column));
        }

        public SqlSingle GetSqlSingle(string column)
        {
            return Reader.GetSqlSingle(Reader.GetOrdinal(column));
        }

        public SqlString GetSqlString(string column)
        {
            return Reader.GetSqlString(Reader.GetOrdinal(column));
        }

        public object GetSqlValue(string column)
        {
            return Reader.GetSqlBoolean(Reader.GetOrdinal(column));
        }

        public int GetSqlValues(object[] values)
        {
            return Reader.GetSqlValues(values);
        }

        public SqlXml GetSqlXml(string column)
        {
            return Reader.GetSqlXml(Reader.GetOrdinal(column));
        }

        public Stream GetStream(string column)
        {
            return Reader.GetStream(Reader.GetOrdinal(column));
        }

        public string GetString(string column)
        {
            return Reader.GetString(Reader.GetOrdinal(column));
        }

        public TextReader GetTextReader(string column)
        {
            return Reader.GetTextReader(Reader.GetOrdinal(column));
        }

        public TimeSpan GetTimeSpan(string column)
        {
            return Reader.GetTimeSpan(Reader.GetOrdinal(column));
        }

        public object GetValue(string column)
        {
            return Reader.GetValue(Reader.GetOrdinal(column));
        }

        public int GetValues(object[] values)
        {
            return Reader.GetValues(values);
        }

        public XmlReader GetXmlReader(string column)
        {
            return Reader.GetXmlReader(Reader.GetOrdinal(column));
        }

        public bool IsDBNull(string column)
        {
            return Reader.IsDBNull(Reader.GetOrdinal(column));
        }

        public async Task<bool> IsDBNullAsync(string column, CancellationToken cancellationToken)
        {
            return await Reader.IsDBNullAsync(Reader.GetOrdinal(column), cancellationToken);
        }

        public bool NextResult()
        {
            return Reader.NextResult();
        }

        public async Task<bool> NextResultAsync(CancellationToken cancellationToken)
        {
            return await Reader.NextResultAsync(cancellationToken);
        }

        public bool Read()
        {
            return Reader.Read();
        }

        public async Task<bool> ReadAsync(CancellationToken cancellationToken)
        {
            return await Reader.ReadAsync(cancellationToken);
        }

        #endregion Public Methods
    }
}
